// include/string.h
// <ChenJie> : 2006-10-02

#ifndef STRING_H
#define STRING_H

extern inline int strlen(const char *s)
{
	register int len;
	__asm__("\tcld\n"
		"\trepne\n"
		"\tscasb\n"
		"\tnotl %0\n"
		"\tdecl %0\n"
		:"=c"(len)
		:"D"(s), "a"(0), "c"(0xffffffff)
	       );
	return len;
}

extern inline char * strcpy(char *dest, const char *src)
{
	__asm__("\tcld\n"
		"1:\tlodsb\n"
		"\tstosb\n"
		"\ttestb %%al, %%al\n"
		"\tjne 1b\n"
		::"S"(src), "D"(dest)
	       );
	return dest;
}

extern inline void * memcpy(void *dest, const void *src, unsigned long n)
{
	__asm__("\tcld\n"
		"\trep\n"
		"\tmovsb\n"
		::"c"(n),"S"(src),"D"(dest)
	       );
	return dest;
}

#endif //STRING_H
